#include "bullet.h"

bullet::bullet()
{
    //加载子弹资源
    m_Bullet.load(BULLET_PATH1);

    //子弹坐标
    m_x=GAME_WIDTH*0.5-m_Bullet.width()*0.5;
    m_y=GAME_HEIGHT;

    //子弹状态默认空闲
    m_free=true;

    //子弹速度
    m_speed =BULLET_SPEED;

    //子弹边框
    m_Rect.setWidth(m_Bullet.width());
    m_Rect.setHeight(m_Bullet.height());
    m_Rect.moveTo(m_x,m_y);

}

void bullet::updatePosition()
{
    //空闲状态下的子弹，不需要计算坐标
    if (m_free)
    {
        return;
    }

    //子弹向上移动
    m_y -= m_speed;
    m_Rect.moveTo(m_x,m_y);

    //子弹位置超出屏幕,重新变为空闲状态
    if(m_y<=-m_Rect.height())
    {
        m_free=true;
    }

}
